package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自动装配minio到ioc容器同时创建minioClient对象加载到ioc容器
 */
@ConditionalOnProperty(prefix = "minio" ,value = "endpoint")
@Configuration
@EnableConfigurationProperties(MinioProperties.class)
public class MinioConfiguration {

    @Autowired
    private MinioProperties properties;

    @Bean
    public MinioClient minioClient() {
        return
                MinioClient.builder().endpoint(properties.getEndpoint()).credentials(properties.getAccessKey(),
                        properties.getSecretKey()).build();
    }
}
